

sf::Color Get_pixel ( sf::Sprite *image ,Sint64 x ,Sint64 y )
{
    return image->GetPixel(x, y);
}

sf::Color Get_pixel(sf::Image *image, Sint64 x, Sint64 y){

    return image->GetPixel(x, y);

}

void inline Set_pixel ( sf::Image *image ,Sint64 x ,Sint64 y , sf::Color colour )
{
        image->SetPixel(x, y, colour);
}




class Image
{
public:
    int Del;
    int r;

        sf::Image data;

        sf::Sprite image;

        preciserect Dest, Src;

        std::string Name;

        int Transparency;

        Image() {
                Transparency=0;
                Dest.x=0;
                Dest.y=0;
                Dest.h=0;
                Dest.w=0;
                Src.x=0, Src.y=0, Src.h=0, Src.w=0;

        }

        Image(std::string pName,  Sint64 x=0, Sint64 y=0, int pTransparency=0) {

                Load(pName, x, y, pTransparency);


        }

        int Load(std::string pName, Sint64 x=0, Sint64 y=0,  int pTransparency=0) { ///This is the default co-ordinates, not the coords to load from
                r=0; ///Draw insame place regardless of camera
                Name=pName;
                Del=0;
                Transparency=pTransparency;
                Dest.x=x;
                Dest.y=y;

                /*SDL_Surface *temp=0;
                temp = SDL_LoadBMP(Name.c_str());
                if (temp == NULL) {

                        std::cout <<"LoadImageFailed!: " << Name << std::endl;

                        SDL_FreeSurface(temp);
                        return 1;
                }



                Surface = SDL_DisplayFormat(temp);
                SDL_FreeSurface(temp);*/
                data.LoadFromFile(Name);

                image.SetImage(data);
                Dest.h=data.GetHeight();
                Dest.w=data.GetWidth();

                //Src=Dest;
                Src.x=0;
                Src.y=0;
                Src.w=data.GetWidth();
                Src.h=data.GetHeight();
                return 0;

        }

        //SDL_Surface *return_surface_pointer() {
          //      return Surface;
        //}



        ~Image() {
            if(Del==1){}
                //SDL_FreeSurface(Surface);
                //image.DestroyTexture();
        }

        void update_to_surface(Sint64 x=0, Sint64 y=0) {

                Dest.x=x;
                Dest.y=y;

                Dest.h=data.GetHeight();
                Dest.w=data.GetWidth();

                Src.x=0;
                Src.y=0;
                Src.w=data.GetWidth();
                Src.h=data.GetHeight();

                image.SetImage(data);


        }

        void add_to_pixel(Sint64 x, Sint64 y, sf::Color Colourr){

        sf::Color Col=Get_pixel(&data,  x,  y);


        if(Colourr.r+Col.r<=255 && Colourr.r+Col.r>=0){

            Col.r+=Colourr.r;

        }
        else if(Colourr.r+Col.r<0){
            Col.r=0;
        }
        else{
            Col.r=255;
        }
        if(Colourr.g+Col.g<=255&& Colourr.g+Col.g>=0){

            Col.g+=Colourr.g;


        }
        else if(Colourr.g+Col.g<0){
            Col.g=0;

        }

        else{
            Col.g=255;
        }
        if(Colourr.b+Col.b<=255&& Colourr.b+Col.b>=0){

            Col.b+=Colourr.b;

        }
        else if(Colourr.b+Col.b<0){
            Col.b=0;

        }
        else{
            Col.b=255;
        }
        Set_pixel(&data, x, y, Col);


        //Set_pixel2(Surface, x, y, Colour);

        }



        void create_surface(Sint64 width, Sint64 height) {

                //Surface=SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0,0,0,0);
                data.Create(width, height);
                update_to_surface();
                //Del=1;
        }




        sf::Color get_pixel(Sint64 x, Sint64 y){

            return Get_pixel(&data, x, y);

        }

        void set_pixel(Sint64 x, Sint64 y, sf::Color Colour){
            Set_pixel(&data, x, y, Colour);
        }


};
